﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Text;
using Common;


public partial class admin_finance_customerinfoeidotr : PageBase
{
    public string PageTitle = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Expires = -1;
        PageBegin("customer manage", 1); 

        ///保存
        if (RequestBase.GetFormString("__EVENTTARGET") == "save")
        {
            SaveInfo();
        }

        if (!IsPostBack)
        {  
            if (RequestBase.GetQueryString("otype") == "modify")
            {
                PageTitle = "Modify";
                Initialize();
            }
            else
            {
                PageTitle = "Add";
            }
        }
    }

    #region 信息初始化
    void Initialize()
    {
        GetObj = BLL.LED.CustomerBase.GetCustomerObjById(RequestBase.GetQueryString("customerid"));
    }

    ///// <summary>
    ///// 信息实体
    ///// </summary>
    Model.LED.CustomerBase GetObj
    {
        get
        {
            Model.LED.CustomerBase _obj = new Model.LED.CustomerBase();

            if (!string.IsNullOrEmpty(RequestBase.GetQueryString("customerid").Trim()))
            {
                _obj.CustomerId = RequestBase.GetQueryString("customerid").Trim();
            }

            _obj.CustomerName = txtCustomerName.Value.Trim();
            _obj.CustomerNumber = "";
            _obj.Phone = txtPhone.Value.Trim();
            _obj.Email = txtEmail.Value.Trim();
            _obj.Contactperson = txtContactperson.Value.Trim();
            _obj.ContactpersonPhone = txtContactpersonPhone.Value.Trim();
            _obj.Description = txtDescription.Value.Trim();

            _obj.CreatedBy = this.SystemUserId;
            _obj.ModifyBy = _obj.CreatedBy;
            _obj.ModifyOn = DateTime.Now;
            _obj.CreatedOn = DateTime.Now;

            return _obj;
        }
        set
        {
            if (value != null)
            {
                txtCustomerName.Value = value.CustomerName;
                txtPhone.Value = value.Phone;
                txtEmail.Value = value.Email;
                txtContactperson.Value = value.Contactperson;
                txtContactpersonPhone.Value = value.ContactpersonPhone;
                txtDescription.Value = value.Description;
            }
        }
    }
    #endregion

    void SaveInfo()
    {
        string res = "";

        if (RequestBase.GetQueryString("otype").Trim() == "add")
        {
            res = BLL.LED.CustomerBase.Add(GetObj);
        }
        if (RequestBase.GetQueryString("otype").Trim() == "modify")
        {
            res = BLL.LED.CustomerBase.Modify(GetObj);
        }

        switch (res.Split('|')[0])
        {
            case "succeeded":
                if (RequestBase.GetQueryString("otype") == "add")
                {
                    if (RequestBase.GetFormString("__EVENTARGUMENT") == "saveandclose")
                        JScript.AlertAndReturnValueToParent("Save succeeded!", "window.opener.LoadingData(); window.close();");
                    else
                        JScript.AlertAndRedirect("Save succeeded!", RequestBase.GetUrl());
                }
                else
                {
                    if (RequestBase.GetFormString("__EVENTARGUMENT") == "saveandclose")
                        JScript.AlertAndReturnValueToParent("Save succeeded!", "window.opener.LoadingData(); window.close();");
                    else
                        JScript.AlertAndRedirect("Save succeeded!", RequestBase.GetUrl());
                }
                break;
            default:
                JScript.Alert(res);
                break;
        }
    }
}
